// 首页工作台接口
import { http } from "@/utils/http";

import { whReqBaseUrl as VITE_REQUEST_BASE_SAAS_API } from "@/api/common";

import {
  type requestResultType,
  type publicityListResultType,
  type healthStatisticsType,
  type propStrValueAnyType
} from "@/api/types";

/** 城市健康数据 */
export const getCityHealthStatistics = (
  isNationwide: number,
  provinceId: string,
  cityId: string,
  areaId: string
) => {
  // console.log("getLogin data:", data);
  const params: Record<string, any> = {
    isNationwide,
    provinceId: provinceId
  };
  if (cityId) {
    params.cityId = cityId;
  }
  if (areaId) {
    params.areaId = areaId;
  }

  return http.get<healthStatisticsType>(
    `${VITE_REQUEST_BASE_SAAS_API}/index/cityHealthStatistics`,
    {
      params
    }
  );
};

// 获取宣传方案列表

export const getPublicityGrogrammes = () => {
  // console.log("getLogin data:", data);
  return http.get<publicityListResultType>(
    `${VITE_REQUEST_BASE_SAAS_API}/contentManagements`,
    {
      params: {
        skip: 0,
        limit: 5,
        type: 2
      }
    }
  );
};

// 获取当时消息列表
export const getMessageList = () => {
  // console.log("getLogin data:", data);
  return http.get<publicityListResultType>(
    `${VITE_REQUEST_BASE_SAAS_API}/contentManagements`,
    {
      params: {
        skip: 0,
        limit: 5,
        type: 1
      }
    }
  );
};

// 获取当日数据
export const getDayStatistics = (
  isNationwide: number,
  provinceId: string,
  cityId: string,
  areaId: string
) => {
  const params: Record<string, any> = {
    isNationwide,
    provinceId: provinceId
  };
  if (cityId) {
    params.cityId = cityId;
  }
  if (areaId) {
    params.areaId = areaId;
  }
  return http.get<propStrValueAnyType>(
    `${VITE_REQUEST_BASE_SAAS_API}/index/dayStatistics`,
    {
      params
    }
  );
};

// 1=实际支付订单 2=实际收款金额 3=非医保收款金额 4=新增用药管理会员 5=新增预约单 6=新增保单
// 当日数据明细
type dayStaListType = Array<{
  dateTime: string;
  quantity: string;
}>;
export const getDayStatisticsDetail = (
  queryDate?: string,
  isNationwide?: number,
  provinceId?: string,
  cityId?: string,
  areaId?: string
) => {
  const params: Record<string, any> = {
    queryDate,
    isNationwide,
    provinceId: provinceId
  };
  if (cityId) {
    params.cityId = cityId;
  }
  if (areaId) {
    params.areaId = areaId;
  }
  return http.get<dayStaListType>(
    `${VITE_REQUEST_BASE_SAAS_API}/index/dayStatisticDetail`,
    {
      params
    }
  );
};
